package com.cloudy.s3.request;

import java.util.Map;

import com.cloudy.exception.AWSAccessException;
import com.cloudy.impl.S3Object;
import com.cloudy.impl.SuccessHandlerWithNoResponse;
import com.cloudy.s3.response.MetadataEntry;

public class StoreObject extends S3Request{
	public static final String CONTENT_ENCODING = "Content-Encoding";
	public static final String CACHE_CONTROL = "Cache-Control";
	public static final String CONTENT_DISPOSITION = "Content-Disposition";
	public static final String X_AMZ_ACL = "x-amz-acl";
	public static final String X_AMZ_META = "x-amz-meta-";
	public StoreObject(String bucketName, String objectName ,S3Object object) {
		super(bucketName, "PUT");
		super.setSuccessHandler(new SuccessHandlerWithNoResponse());
		super.resource = objectName;
		super.setS3Object(object);
		
	}
	public StoreObject setCacheControl(String cacheControl) {
		super.getS3Object().addHeader(cacheControl, S3Object.CACHE_CONTROL);
		super.addHeader(CACHE_CONTROL, cacheControl);
		return this;
	}
	public StoreObject setContentDisposition(String contentDisposition) {
		super.getS3Object().addHeader(contentDisposition, S3Object.CONTENT_DISPOSITION);
		super.addHeader(CONTENT_DISPOSITION, contentDisposition);
		return this;
	}

	public StoreObject setContentEncoding(String contentEncoding) {
		super.getS3Object().addHeader(contentEncoding, S3Object.CONTENT_ENCODING);
		super.addHeader(CONTENT_ENCODING, contentEncoding);
		return this;
	}
	public StoreObject setCannedAccessPolicy(CannedAccessControl accessControl){
		super.addHeader(X_AMZ_ACL, accessControl.toString());
		return this;
	}

	public StoreObject setUserMetaData(String name, String value) {
		super.addHeader(X_AMZ_META+name, value);
		return this;
	}
	
	public enum CannedAccessControl{
		PRIVATE("private"),
		PUBLIC_READ("public-read"),
		PUBLIC_READ_WRITE("public-read-write"),
		AUTHENTICATED_READ("authenticated-read");

		private final String value;
		CannedAccessControl(String value){
			this.value = value;
		}
		@Override
		public String toString() {
			return value;
		}
		
	}
	public Map<String, MetadataEntry> execute() throws AWSAccessException{
		return executeInner().getMetadataEntries();
	}

}
